package com.pd.modules.common;

public class SimpleEncryptionUtils implements EncryptionUtils
{

	public byte[] encryptBuffer(byte[] _buffer, byte[] _key)
	{
		// XOR _key[i]
		// ADD 2
		// XOR _key[i]

		int keyIdx = 0;
		for (int i = 0; i < _buffer.length; keyIdx++, i++)
		{
			if (keyIdx >= _key.length)
				keyIdx = 0;

			_buffer[i] ^= _key[keyIdx];
			_buffer[i] += 2;
			_buffer[i] ^= _key[keyIdx];
		}

		return _buffer;
	}

	public byte[] decryptBuffer(byte[] _buffer, byte[] _key)
	{
		// XOR _key[i]
		// SUB 2
		// XOR _key[i]

		int keyIdx = 0;
		for (int i = 0; i < _buffer.length; keyIdx++, i++)
		{
			if (keyIdx >= _key.length)
				keyIdx = 0;

			_buffer[i] ^= _key[keyIdx];
			_buffer[i] -= 2;
			_buffer[i] ^= _key[keyIdx];
		}

		return _buffer;
	}
}